package sjjg.op;

import java.util.*;

public class FIFO {
    private List<Integer> pageSpace;

    private int capacity=3;

    private Scanner scanner=new Scanner(System.in);

    public FIFO() {
        pageSpace=new ArrayList<>(3);
    }
    public FIFO(int capacity){
        this.capacity=capacity;
        pageSpace=new ArrayList<>(capacity);
    }
    public void start(char[]str){
        float count=0;
        for(int i=0;i<str.length;i++){
            int page=str[i]-48;
            if(!pageSpace.contains(page)){
                if(pageSpace.size()==capacity) pageSpace.remove(0);
                pageSpace.add(page);
                System.out.println(pageSpace);
            }else {
                count++;
            }
        }
        System.out.println("命中率为："+count/str.length);
    }
    public static void main(String[] args) {
          char[]chars={'7','0','1','2','0','3','0','4','2','3','0','3','2','1','2','0','1','7','0','1'};
          new FIFO(3).start(chars);
    }
}
